
from PIL import Image
import numpy as np

def compare_images(image_path1, image_path2):
    image1 = Image.open(image_path1)
    image2 = Image.open(image_path2)

    if image1.size != image2.size:
        return "Images are of different sizes."

    image1_np = np.array(image1)
    image2_np = np.array(image2)

    difference = image1_np - image2_np
    similarity = 1 - (np.sum(np.abs(difference)) / (255.0 * image1_np.size))
    return similarity







if __name__ == '__main__':
    print('PyCharm')
    # 使用示例
    # correlation = compare_histograms('D:/FaceDetect/1.jpg', 'D:/FaceDetect/2.jpg')
    # print(f"Histogram correlation: {correlation}")
    # 使用示例
    # num_matches = compare_features('D:/FaceDetect/1.jpg', 'D:/FaceDetect/2.jpg')
    # print(f"Number of feature matches: {num_matches}")
    # 使用示例
    similarity = compare_images('D:/FaceDetect/1.jpg', 'D:/FaceDetect/2.jpg')
    print(f"Image similarity: {similarity}")




